Skip to content

go/callgraph/rta: memoize method lookups in addInvokeEdge - #675

Open
hungcs wants to merge 1 commit into
golang:masterfrom
hungcs:rta-method-memo-pr
Open

go/callgraph/rta: memoize method lookups in addInvokeEdge#675
hungcs wants to merge 1 commit into
golang:masterfrom
hungcs:rta-method-memo-pr

Conversation

@hungcs

@hungcs hungcs commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Second follow-up to golang/go#81308.

addInvokeEdge runs for every (invoke site, runtime type) pair in the
dynamic dispatch matrix. Many sites share the same interface method and
concrete type, so LookupMethod repeats the same method set search,
rebuilding method Id strings and comparing them, once per site.

This CL caches the result per (interface method object, concrete type).
Both keys are pointer-identical across calls, so a hit is a single map
lookup with no string building and no type hashing.

Makes deadcode ~25% faster on a benchmark of kubernetes/cmd/kubelet on
top of #674 (6.55s to 4.93s)

Updates golang/go#81308

addInvokeEdge runs for every (invoke site, runtime type) pair in the
dynamic-dispatch matrix, and many sites share the same interface method
and concrete type, so LookupMethod repeats the same method-set search —
rebuilding method Id strings and comparing them — for each one. Cache the
result per (interface method object, concrete type); both keys are
pointer-identical across calls, so a hit is a single map lookup with no
strings and no type hashing. Memory is bounded by the number of distinct
pairs, a small fraction of call volume.

On a 1,132-package monorepo, whole-program deadcode analysis drops from
210s to 156s wall (CPU 322s to 234s), with identical findings. Combined
with CL 826224 and the MethodValue fast path, analysis is now faster than
x/tools v0.45.0 was before generic-method support (186s on the same
hardware against a smaller Go 1.26 tree).

Updates golang/go#81308
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 9887c22) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/tools/+/827504.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Hung-wei Chuang:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/827504.
After addressing review feedback, remember to publish your drafts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants